function [t_a,t_d,t_c,t_t]=costPlanner(vel_i,vel_f,dist,dv)
%totalTravel(vel_i,vel_f,dist,a)
%   Vel_i: Starting speed of planet (must be positive)
%	Vel_f: Speed of destination (can be negative if headed away from you!)
%	Dir: Direction of body. 1 if traveling away, 0 if approaching
%	Dist: Disance to cover (in AU)
%	dv: Total DV avliable for manuver.

%% Convert to SI
a=9.80665;
dist=dist*150e9;


%% Error Checking
% Check to see if given DV is enough
if(abs(vel_f-vel_i)>dv)
	fprintf('You need at least %.2f m/s of DV to make the trip!\n',abs(vel_f-vel_i));
	error('Not enough DV for the trip!');
end

%% Calc DV resource
dv_r=dv-abs(vel_f-vel_i);
dv_a=dv-dv_r;

%% Calculate Departure
t_a=(vel_i+dv_a)/a+dv_r/2/a;	% Time for departure burn (s)

%% Calculate Coasting Speed
vel_trav=vel_i+dv_a+dv_r/2;

%% Calcuate arrival burn
t_d=abs(vel_trav-vel_f)/a;

%% Calculate Coasting Time
dist_a=vel_i*t_a+0.5*a*t_a^2;
dist_d=vel_trav*t_d+0.5*a*t_d^2;
dist_c=dist-dist_a-dist_d;
t_c=dist_c/vel_trav;
if(t_c<0)
	error('Coasting time is negative, you need more acceleration or less dv');
end

t_t=t_a+t_d+t_c;

%% Ouput
fprintf('**Course Calculated!***\n');
fprintf('Final Speed:\n   %.2f (m/s)\n',vel_trav);
fprintf(['Time (accel):\n',time2str(t_a)]);
fprintf(['Time (decel):\n',time2str(t_d)]);
fprintf(['Time (coast):\n',time2str(t_c)]);
fprintf(['Time (total):\n',time2str(t_t)]);

end


%% Math Work
% x(ship)=0+vel_trav*t
% x(target)=0+vel_f*t
%
